package com.jcnet.bizaia;
import com.jcnet.bizaia.bean.VoiceDetailBean;
import com.jcnet.bizaia.fragment.VoiceTalkFragment;
import com.jcnet.bizaia.tools.JCTools;
import com.squareup.picasso.Picasso;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class VoiceTalkActivity extends JCSimpleSherlockActivity {

	private VoiceDetailBean voiceDetailBean;
	
	private ImageView authorImg;
	
	private VoiceTalkFragment voiceTalkFragment;
	
	
	private EditText talkEditText;

	private ImageView userImgView;

	private Button commitButton;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.jcTitle = getString(R.string.voiceTalk);
		super.initActionBar();
		super.onCreate(arg0);
		setContentView(R.layout.voice_talk_lay);
		voiceDetailBean = (VoiceDetailBean) getIntent().getSerializableExtra("voiceDetailBean");
		
		findViewById(R.id.vodInfo).setVisibility(View.GONE);
		
		talkEditText = (EditText)findViewById(R.id.talkContent);

		userImgView = (ImageView)findViewById(R.id.talk_img);

		commitButton = (Button)findViewById(R.id.commitTalk);
		
		Picasso.with(this).load(App.HTTP_PATH+JCTools.getUserBean(this).getUserimage()).resize(80, 80).into(userImgView);
		
		commitButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				System.out.println("d点击了阿牛");
				
				Intent intent = new Intent(VoiceTalkFragment.TALK_CHANGE);
				intent.putExtra("didNum", voiceDetailBean.getSid());
				intent.putExtra("content", talkEditText.getText().toString());
				sendBroadcast(intent);
				
				talkEditText.setText("");
				
			}
		});
		
		
		
		
		
		
		voiceTalkFragment = VoiceTalkFragment.newInstance(voiceDetailBean.getSid());
		getSupportFragmentManager().beginTransaction().replace(R.id.baseFragment, voiceTalkFragment).commit();
		
		
		
		authorImg = (ImageView)findViewById(R.id.voiceTalkImg);
		
		System.out.println("音频ID="+voiceDetailBean.getSid());
		
		if(voiceDetailBean!=null){
			((TextView)findViewById(R.id.voiceTalkData)).setText(voiceDetailBean.getDateline());
			Picasso.with(VoiceTalkActivity.this).load(App.HTTP_PATH+voiceDetailBean.getAcsimages()).centerCrop().resize(100, 80).into(authorImg);
			((TextView)findViewById(R.id.voiceTalkAuthor)).setText(voiceDetailBean.getCsname());
			((TextView)findViewById(R.id.voiceTalkContent)).setText(voiceDetailBean.getContent());
			
		}
		
	}
}
